package com.lagou.bio;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class BIOClient2 {

    public static void main(String[] args) throws Exception {
        while (true) {
            // 创建socket对象
            Socket socket = new Socket("127.0.0.1", 9999);
            // 取出输出流并传递信息
            OutputStream outputStream = socket.getOutputStream();
            System.out.println("请输入:");
            Scanner scanner = new Scanner(System.in);
            String msg = scanner.nextLine();
            outputStream.write(msg.getBytes());
            // 取出输入流并接收信息
            InputStream inputStream = socket.getInputStream();
            byte[] bytes = new byte[1024];
            int read = inputStream.read(bytes);
            System.out.println("老板说:" + new String(bytes, 0, read));
            socket.close();
        }
    }
}
